package Offer05;

/**
 * 替换空格
 * @author 23737
 * @time 2021.10.15
 */
public class Test {
    public static void main(String[] args) {
        String s = "we are family";
        System.out.println(new Solution().replaceSpace(s));
    }
}

class Solution {
    public String replaceSpace(String s) {
//        return s.replaceAll(" ","%20");

        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == ' ') {
                stringBuilder.append("%20");
            }else {
                stringBuilder.append(c);
            }
        }
        return String.valueOf(stringBuilder);
    }
}
